package org.thingsboard.server.dao.jpa.imp;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.thingsboard.server.dao.jpa.TDeviceModel;
import org.thingsboard.server.dao.jpa.TGateway;
import org.thingsboard.server.dao.util.SqlDao;

import java.util.List;

@SqlDao
public interface DeviceModelRepository extends CrudRepository<TDeviceModel, String> {


    /**
     * 根据网关获取网关下面的所有模型
     * @param gatewayCode
     * @return
     */
    @Query("SELECT DISTINCT a from TDeviceModel a LEFT JOIN TDevice b on a.modelCode=b.modelCode WHERE b.gatewayCode= :gatewayCode")
    List<TDeviceModel> findModels(@Param("gatewayCode")String gatewayCode);

}
